﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;

public partial class frmPlanilla2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        Lcuit.Text = Session["cuit"].ToString();
        Lrazon.Text = Session["razon"].ToString();
        Lnombre.Text = Session["nombre"].ToString();
        Lcalle.Text = Session["calle"].ToString();
        Lnumero.Text = Session["numero"].ToString();
        Lpiso.Text = Session["piso"].ToString();
        Ldpto.Text = Session["dpto"].ToString();
        Lbarrio.Text = Session["barrio"].ToString();
        Llocalidad.Text = Session["localidad"].ToString();
        Lcodigo.Text = Session["codigo"].ToString();
        Ltelefono.Text = Session["telefono"].ToString();

        LnombreEst.Text = Session["nombreEst"].ToString();
        LcalleEst.Text = Session["calle"].ToString();
        LnumeroEst.Text = Session["numero"].ToString();
        LpisoEst.Text = Session["piso"].ToString();
        LdptoEst.Text = Session["dpto"].ToString();
        LbarrioEst.Text = Session["barrio"].ToString();
        LlocalidadEst.Text = Session["localidad"].ToString();
        LcodigoEst.Text = Session["codigo"].ToString();
        LtelefonoEst.Text = Session["telefonoEst"].ToString();
        LmailEst.Text = Session["mailEst"].ToString();
        LRNE.Text = Session["RNE"].ToString();

       
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {
        FileStream fs = new FileStream(Server.MapPath("~/") + "planilla2" + Lrazon.Text + DateTime.Now.ToString("ddMMyy") + ".pdf", FileMode.Create, FileAccess.Write, FileShare.None);
        Rectangle rec3 = new Rectangle(PageSize.A4);
        Document doc = new Document(rec3, 2, 2, 10, 18);
        PdfWriter writer = PdfWriter.GetInstance(doc, fs);
        iTextSharp.text.Font fontTitle = FontFactory.GetFont("Arial", 18, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
        iTextSharp.text.Font fontHead = FontFactory.GetFont("Arial", 16, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
        iTextSharp.text.Font fontBody = FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.BOLD, BaseColor.BLACK);

        Console.WriteLine("");

        doc.Open();


        iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(2);
        PdfPCell cell = new PdfPCell(new Phrase("PLANILLA Nº2"));
        cell.Colspan = 3;
        cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        PdfPCell cell2 = new PdfPCell(new Phrase("Datos del Establecimiento"));
        cell2.Colspan = 3;
        cell2.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell);
        table.AddCell(cell2);

        PdfPCell cell3 = new PdfPCell(new Phrase("NOMBRE DEL ESTABLECIMIENTO: " + LnombreEst.Text));
        cell3.Colspan = 3;
        table.AddCell(cell3);

        PdfPCell cell4 = new PdfPCell(new Phrase("DOMICILIO DEL ESTABLECIMIENTO:"));
        cell4.Colspan = 3;
        cell4.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell4);

        PdfPCell cell5 = new PdfPCell(new Phrase("Calle: " + LcalleEst.Text + " Numero: " + LnumeroEst.Text + "     Barrio: " + LbarrioEst.Text));
        cell5.Colspan = 3;
        cell5.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell5);

        PdfPCell cell6 = new PdfPCell(new Phrase("Localidad: " + LlocalidadEst.Text + "                            Codigo Postal: " + LcodigoEst.Text));
        cell6.Colspan = 3;
        cell6.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell6);

        table.AddCell("Telefono: " + LtelefonoEst.Text);
        table.AddCell("Fax: ");
        PdfPCell cell9 = new PdfPCell(new Phrase("Correo Electronico: " + LmailEst.Text));
        cell9.Colspan = 3;
        cell9.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell9);

        table.AddCell("NUMERO DE RNE: " + LRNE.Text);
        table.AddCell("Expte Nº: "+ TextBox4.Text);

        PdfPCell cell10 = new PdfPCell(new Phrase("Fecha de Otorgamiento del RNE: "));
        cell10.Colspan = 3;
        cell10.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell10);

        PdfPCell cell11 = new PdfPCell(new Phrase("Rubros Autorizados: "+ TextBox7.Text));
        cell11.Colspan = 3;
        cell11.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell11);

        PdfPCell cell12 = new PdfPCell(new Phrase("Nº de Habilitacion MAGyA: "+TextBox5.Text));
        cell12.Colspan = 3;
        cell12.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell12);

        PdfPCell cell13 = new PdfPCell(new Phrase("Nº de Habilitacion SENASA: " + TextBox6.Text));
        cell13.Colspan = 3;
        cell13.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell13);

        PdfPCell cell14 = new PdfPCell(new Phrase("Días y Horarios de Trabajo: "+TextBox8.Text));
        cell14.Colspan = 3;
        cell14.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell14);


        PdfPCell cell7 = new PdfPCell(new Phrase("DATOS DE LA FIRMA PROPIETARIA"));
        cell7.Colspan = 3;
        cell7.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell7);

        PdfPCell cell15 = new PdfPCell(new Phrase("Denominacion de la Firma: " + Lrazon.Text));
        cell15.Colspan = 3;
        cell15.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell15);

        PdfPCell cell16 = new PdfPCell(new Phrase("Forma Juridica de la Firma: "+ TextBox1.Text));
        cell16.Colspan = 3;
        cell16.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell16);

        PdfPCell cell8 = new PdfPCell(new Phrase("DOMICILIO LEGAL"));
        cell8.Colspan = 3;
        cell8.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell8);

        table.AddCell("Calle: " + Lcalle.Text + " Nro: " + Lnumero.Text);
        table.AddCell("Barrio: " + Lbarrio.Text);
        table.AddCell("Localidad: " + Llocalidad.Text);
        table.AddCell("Codigo Postal: " + Lcodigo.Text);
        table.AddCell("Telefono: " + Ltelefono.Text);
        table.AddCell("FAX: ");

        PdfPCell cell17 = new PdfPCell(new Phrase("Correo Electronico: "));
        cell17.Colspan = 3;
        cell17.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell17);

        PdfPCell cell18 = new PdfPCell(new Phrase("Numero de CUIT: " + Lcuit.Text));
        cell18.Colspan = 3;
        cell18.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell18);

        PdfPCell cell19 = new PdfPCell(new Phrase("Numero de INGRESOS BRUTOS: "+TextBox2.Text));
        cell19.Colspan = 3;
        cell19.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell19);

        PdfPCell cell20 = new PdfPCell(new Phrase("Nombre del Representante: "+TextBox3.Text));
        cell20.Colspan = 3;
        cell20.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell20);

        PdfPCell cell21 = new PdfPCell(new Phrase("DATOS DEL DIRECTOR TECNICO"));
        cell21.Colspan = 3;
        cell21.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell21);

        table.AddCell("Apellido y Nombre: "+Label26.Text+" "+Label25.Text);
        table.AddCell("DNI: "+Label37.Text);
        table.AddCell("Profesion: "+TextBox9.Text);
        table.AddCell("Matricula Nº: "+TextBox10.Text);

        PdfPCell cell22 = new PdfPCell(new Phrase("Domicilio"));
        cell22.Colspan = 3;
        cell22.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell22);
        table.AddCell("Calle: " + Label31.Text + " " + " Nº:" + Label32.Text + "  Piso:" + Label33.Text + "  Dpto:" + Label34.Text);
        table.AddCell("Barrio: "+Label35.Text);
        table.AddCell("Localidad: "+Label36.Text);
        table.AddCell("Código Postal: "+Label38.Text);
        table.AddCell("Teléfono: "+Label29.Text);
        table.AddCell("FAX: ");
        PdfPCell cell23 = new PdfPCell(new Phrase("Correo Electronico: "+Label30.Text));
        cell23.Colspan = 3;
        cell23.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell23);

        PdfPCell cell24 = new PdfPCell(new Phrase("DESE A LA TOTALIDAD DE LOS DATOS VOLCADOS EN ESTE FORMULARIO CARACTER DE DECLARACION JURADA"));
        cell24.Colspan = 3;
        cell24.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell24);

        PdfPCell cell25 = new PdfPCell(new Phrase("                                              ........................... Firma"));
        cell25.Colspan = 3;
        cell25.HorizontalAlignment = 2; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell25);

        doc.Add(table);


        doc.Close();

        Response.ContentType = "application/pdf";
        Response.AddHeader("Content-Disposition", "attachment;filename=orden" + Lrazon.Text + DateTime.Now.ToString("ddMMyy") + ".pdf");
        Response.TransmitFile(Server.MapPath("~/") + "planilla2" + Lrazon.Text + DateTime.Now.ToString("ddMMyy") + ".pdf");





    }
    protected void Button2_Click(object sender, EventArgs e)
    {

        

        this.SqlDataSource2.SelectParameters["legajo"].DefaultValue = this.DropDownList1.SelectedValue;
        this.SqlDataSource2.DataSourceMode = SqlDataSourceMode.DataReader;
        SqlDataReader datos = (SqlDataReader)this.SqlDataSource2.Select(DataSourceSelectArguments.Empty);

        if (datos.Read())
        {
            Label26.Text = datos["apellido"].ToString();
            Label25.Text = datos["nombre"].ToString();
            Label27.Text = datos["legajo"].ToString();
            Label28.Text = datos["descripcionCargo"].ToString();
            Label29.Text = datos["numTelefono"].ToString();
            Label30.Text = datos["dirCorreo"].ToString();
            Label31.Text = datos["calle"].ToString();
            Label32.Text = datos["numeroCalle"].ToString();
            Label33.Text = datos["piso"].ToString();
            Label34.Text = datos["departamento"].ToString();
            Label35.Text = datos["nombreBarrio"].ToString();
            Label36.Text = datos["nombreLocalidad"].ToString();
            Label37.Text = datos["numDocumento"].ToString();
            Label38.Text = datos["codPostal"].ToString();
            
        }


        



    }
}